package main

import (
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"gorm.io/gorm/logger"
	"gorm.io/gorm/schema"
	"log"
	"mxshop_srvs/inventory_srv/model"
	"os"
	"time"
)

func main() {
	// 参考 https://github.com/go-sql-driver/mysql#dsn-data-source-name 获取详情
	dsn := "root:123456@tcp(127.0.0.1:3306)/mxshop_inventory_srv?charset=utf8mb4&parseTime=True&loc=Local"

	newLogger := logger.New(
		log.New(os.Stdout, "\r\n", log.LstdFlags), // io writer
		logger.Config{
			SlowThreshold:             time.Second, // 慢 SQL 阈值
			LogLevel:                  logger.Info, // Log level
			IgnoreRecordNotFoundError: true,        // Ignore ErrRecordNotFound error for logger
			ParameterizedQueries:      false,       // Don't include params in the SQL log
			Colorful:                  true,        // Disable color
		},
	)

	db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{
		NamingStrategy: schema.NamingStrategy{
			SingularTable: true,
		},
		Logger: newLogger,
	})
	if err != nil {
		panic(err)
	}
	//_ = db.AutoMigrate(&model.StockSellDetail{})
	/*	orderDetail := model.StockSellDetail{
			OrderSn: "qdbh-jgx",
			Status:  "1",
			Detail:  []model.GoodsDetail{{1, 2}, {2, 3}},
		}
		db.Create(&orderDetail)*/
	var sellDetail model.StockSellDetail
	db.Where(model.StockSellDetail{OrderSn: "qdbh-jgx"}).First(&sellDetail)
	fmt.Println(sellDetail.Detail)
}
